<template>
  <view class="work-container">
		<!-- 轮播图 -->
		<view class="u-demo-block">
	        <u-swiper
	                :list="data"
	                previousMargin="30"
	                nextMargin="30"
	                circular
	                :autoplay="true"
	                radius="15"
	                bgColor="#ffffff"
	        ></u-swiper>
	    </view>
		<!--滚动通知-->
		<view style="margin-top: 3%;">
		  <u-notice-bar :text="notices" direction="column"></u-notice-bar>
		</view>
		<!-- 宫格组件 -->
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeGrid">
			  <uni-grid-item v-for="(item, index) in category" :key="index" :index="index">
				<view class="grid-item-box">
				  <view class="circle-background">
					<uni-icons custom-prefix="iconfont" :type="item.categoryIcon" size="40" :color="item.color"></uni-icons>
				  </view>
				  <text class="text" :style="{ color: item.color }">{{item.categoryName}}</text>
				</view>
			  </uni-grid-item>
			</uni-grid>
      </view>
	  <view class="card-container">
		    <view class="card" @tap="showPhone">
		      <view class="card-icon">
		        <uni-icons custom-prefix="iconfont" type="icon-chewei-06" size="35" color="#51d6a9"></uni-icons>
		      </view>
		      <view class="card-text">
		        <font color="#51d6a9">邻里电话簿</font>
		      </view>
		    </view>
		    <view class="card" @tap="showSq">
		      <view class="card-icon">
		        <uni-icons custom-prefix="iconfont" type="icon-chewei-06" size="35" color="#51d6a9"></uni-icons>
		      </view>
		      <view class="card-text">
		        <font color="#51d6a9">社区信息</font>
		      </view>
		    </view>
	 </view>
		  
	<view>
		<view class="cardTitleBox">
			<text class="cardTitle">信息汇总</text>
		</view>
			<u-list @scrolltolower="scrolltolower" height="550rpx">
				    <u-list-item v-for="(item, index) in infos" :key="index" >
						<u-cell-group>
							<u-cell :title="item.name"  @click="showInfo(item)" >
								<template #value>
								            <view>
								              <view :style="{color:item.categoryColor,textAlign:'right'}">{{ item.type }}</view>
								              {{ item.communityName }}
								            </view>
								          </template>
							</u-cell>
<!-- 							<u-cell :title="item.name" :titleStyle="{color:item.categoryColor}"  :value="item.type+'\n'+item.communityName"  @click="showInfo(item)" ></u-cell> -->
						</u-cell-group>
				    </u-list-item>
					<u-loadmore :loadmoreText="status" color="#1CD29B"	lineColor="#1CD29B"	dashed	line />
			</u-list>
	</view>  
	<view>
		  <!--#ifdef MP-WEIXIN-->
		  <wu-app-update></wu-app-update>
		  <!--#endif-->
	</view>
	
  </view>
</template>

<script>
import { getCarousel } from "@/api/index/index"
import { getCategory } from "@/api/category/category"
import { getInfos } from "@/api/info/info"
import { getNotices } from "@/api/system/notice"
  export default {
    data() {
      return {
		status: '看,我和别人不一样',
		loadingText: '努力加载中',
		loadmoreText: '轻轻上拉',
		nomoreText: '实在没有了',
        current: 0,
        swiperDotIndex: 0,
		data:[],
		category:[],
		infos:[],
		notices:[],
		isRefreshing: false,
		page: 1,
		pageSize: 10

      }
    },
	created() {
			this.getCarouselIndex()
			this.getCategoryIndex()
			this.getInfoIndex()
			this.getNoticeIndex()
	},
    methods: {
		async onPullDownRefresh() {
		      this.isRefreshing = true;
		      this.page = 1;
		      const data = await this.getInfoIndex();
		      this.list = data;
		      this.isRefreshing = false;
		      this.loadMoreStatus = 'more';
		    },
			
		scrolltolower(){
				this.loadMore()
			},
			
		async loadMore() {
			this.page++;
			this.status=this.loadingText;
			const data = await getInfos({pageSize:this.pageSize,pageNum:this.page,type:''});
			if(this.infos.length==data.total){
				this.status=this.nomoreText;
			}else{
				data.rows.forEach((item, index) => {
					this.infos.push(item);
				});
				this.status=this.status
			}
		 },
		getCarouselIndex() {
			getCarousel().then(res => {
				res.rows.forEach((item, index) => {
					this.data.push(item.showUrl);
				});        
			}).catch(error => {
				console.error("获取轮播数据异常:", error);
			});
		},		
		getCategoryIndex() {
			getCategory().then(res => {
				res.rows.forEach((item, index) => {
					this.category.push(item);
				});        
			}).catch(error => {
				console.error("获取分类数据异常:", error);
			});
		},
		getInfoIndex(){
			getInfos({pageSize:this.pageSize,pageNum:this.page,type:'',status:'2'}).then(res=>{
				this.infos=res.rows
			})
		},
		getNoticeIndex(){
			this.notices=[]
			getNotices().then(res=>{
				res.rows.forEach(item=>{
					this.notices.push(item.noticeTitle)
				})
			})
		},
      clickBannerItem(item) {
        console.info(item)
      },
      changeSwiper(e) {
        this.current = e.detail.current
      },
	  showInfo(item){
		  this.$tab.navigateTo(`/pages/common/content/index?infoId=${item.infoId}`)
	  },
	  showPhone(){
		  this.$tab.navigateTo(`/pages/type/phone`)
	  },
	  showSq(){
		  this.$tab.navigateTo(`/pages/type/sq`)
	  },
      changeGrid(e) {		  
		  console.info(this.category[e.detail.index])
        this.$tab.navigateTo(`/pages/type/index?typeId=`+this.category[e.detail.index].categoryId+"&name="+this.category[e.detail.index].categoryName)
      }
    }
  }
</script>

<style lang="scss">
.card-container {
  display: flex;
  justify-content: space-between;
  background-color: transparent; /* 背景色透明，以便显示阴影 */
  padding: 5px;
  margin-top: -2%;
}

.card {
  width: 49%; /* 调整卡片宽度 */
  height: 70px; /* 调整卡片高度 */
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
  background-color: #ffffff; /* 卡片背景色 */
  border-radius: 8px; /* 圆角 */
  border: 2px solid #51d6a9; /* 上边框 */
}

.card-content {
  text-align: center;
  padding: 10px;
}

.uni-icons {
  margin-bottom: 5px; /* 调整图标与文字的间距 */
}
.cardTitleBox {
				background-color: rgba(72, 186, 91, 0.1);
				border-bottom: 1px solid #F4F4F4;
				padding-left: 8px;
				border-radius: 6px 6px 0 0 ;

				.cardTitle {
					padding-left: 20px;
					font-size: 16px;
					font-weight: 500;
					letter-spacing: 0px;
					line-height: 0px;
					color: rgba(51, 51, 51, 1);
					line-height: 40px;
					position: relative;

				}

				.cardTitle::before {
					content: '';
					display: inline-block;
					width: 4px;
					height: 16px;
					left: 5px;
					top: 3px;
					position: absolute;
					opacity: 1;
					background: rgba(72, 186, 91, 1);
				}
			}	
.list-item {
  padding: 10px;
  border-bottom: 1px solid #eee;
}
.header {
  display: flex;
  justify-content: space-between;
}
.title {
  font-weight: bold;
}
.distance {
  color: #999;
}
.content {
  margin-top: 5px;
}	
.content2 {
  margin-top: 5px;
  color: gray;
}	
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }
.grid-body {
  
}

.circle-background {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  // height: 80px;
  // border-radius: 100px;
  // background-color: #f1f1ff;
  // margin-bottom: 8px;
}

.text {
  margin-top: 8px;
  font-size: 14px;
  color: #333;
}
.grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

.uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

.swiper {
    height: 300rpx;
  }

.swiper-box {
    height: 150px;
  }

.swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

@media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
